package com.xcc.netty.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author frosty
 * @description
 * @date 2019-12-30 30:10:20
 */


public class SerThread implements Runnable {
public  static  int a=1;

    private Socket socket;



    public  SerThread (Socket socket){
       this.socket=socket;

    }



    @Override
    public void run() {
        byte[] buff = new byte[1024];
        int len = 0;
            try {
                InputStream is = socket.getInputStream();
                while (true) {
               if ((len = is.read(buff))!=-1) {
                    System.out.println(Thread.currentThread().getId());
                    System.out.println("客户端消息:" + new String(buff, 0, len, "gbk"));
                    OutputStream os=socket.getOutputStream();
                    os.write(("数据接受完成"+Thread.currentThread().getId()).getBytes("gbk"));
                    os.flush();

                }
                    System.out.println(len);
                }

            } catch (IOException e) {
                e.printStackTrace();
            }

    }
}
